package operation;

import book.BookList;

import java.util.Scanner;

public class DeletOperation implements Iop{
    @Override
    public void work(BookList bookList) {
        System.out.println("删除图书");
        int k = -1;
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入你要删除的书：");
        String name = scanner.nextLine();
        int size = bookList.getNum();
        for (int i = 0; i < size; i++) {
            if (name.equals(bookList.getBooks(i).getName())) {
                k = i;
                break;
            }
        }
        if (k == -1){
            System.out.println("没有这本书");
            return;
        }
            for (int j = k; j < bookList.books.length-1; j++) {
                bookList.setBooks(j, bookList.getBooks(j + 1));
            }
            bookList.setNum(size - 1);
        System.out.println("删除成功！");
        }
    }
